package ch10_thread.thread;

/**
 * 优先选择，传递中断
 *
 * @author guodd
 * @version 1.0 use jdk 1.8
 */
public class StopRightWay01 implements Runnable {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new StopRightWay01());
        thread.start();
        Thread.sleep(1000);
        thread.interrupt();
    }

    @Override
    public void run() {
        // 接收不到中断信息
        while (true) {
            System.out.println("go");
            try {
                interMethod();
            } catch (InterruptedException e) {
                // 进行更多的操作保存日志、终止程序
                System.out.println("记录日志");
                e.printStackTrace();
                break;
            }
        }
    }

    // 此处
    private void interMethod() throws InterruptedException {
        // try {
        Thread.sleep(2000);
        // } catch (InterruptedException e) {
        //     e.printStackTrace();
        // }
    }
}
